<template>
  <div id="add">
    <el-form :model="form" label-width="80px">
      <el-form-item label="角色名称">
        <el-input v-model="form.name" placeholder="请输入角色职务" />
      </el-form-item>
      <el-form-item label="角色描述">
        <el-input
          v-model="form.description"
          placeholder="请输入角色职务的相关描述"
        />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialogShow-footer">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="addSub">确定</el-button>
    </div>
  </div>
</template>

<script>
import { addRoleAPI } from '@/api/index'
export default {
  data() {
    return {
      form: {
        name: '',
        description: ''
      }
    }
  },
  methods: {
    cancel() {
      this.form = {
        name: '',
        description: ''
      }
      this.$emit('guanbi')
    },
    async addSub() {
      if (!this.form.name || !this.form.description) {
        return this.$message.error('内容不能为空')
      }
      const res = await addRoleAPI(this.form)
      // console.log(res)
      this.$message.success(res.message)
      this.form = { name: '', description: '' }
      this.$emit('shuaxin')
    }
  }
}
</script>

<style lang="scss">
.dialogShow-footer {
  text-align: center;
  padding-bottom: 15px;
}
</style>
